<?php
session_start();
define('FPDF_FONTPATH','../pdf/font/');
require('../pdf/fpdf.php');
include('../funct.php');

$pdf=new FPDF();
$pdf->AddFont('Calligrapher','','arial_ce.php');
$pdf->AddPage();
$pdf->Image('../img/logo.png',165,8,33);
$pdf->SetFont('Calligrapher','',9);
$pdf->Text(10, 10, iconv('UTF-8','windows-1250//TRANSLIT',"NIEPUBLICZNY ZAKŁAD OPIEKI ZDROWOTNEJ"));
$pdf->Text(30, 13, "DARMEDICUS");
$pdf->SetFont('Calligrapher','',8);
$pdf->Text(18, 16, "04-364 Warszawa, ul. Wiatraczna 15 lok - U1");
$pdf->Text(29, 19, "tel/fax (22) 465 17 91");
$sql="select DATE_FORMAT(wizyty.data, '%Y-%m-%d') from wizyty where wizyty.id = ".$_GET['wiz'];
$result=mysql_query($sql);
$dat = @mysql_fetch_array($result);

$pdf->Text(175, 43, $dat[0]);
$pdf->Ln(15);
$pdf->SetFont('Calligrapher','',14);
$pdf->MultiCell(0,10,'Zalecenia', 0, "C");

$sql="select pac.pac_nazwisko, pac.pac_imie, pac.pac_pesel from pac, wizyty where wizyty.id_pac = pac.id and wizyty.id = ".$_GET['wiz'];
$result=mysql_query($sql);
$pac = @mysql_fetch_array($result);
$pac['naz']=$pac[0];
$pac['imie']=$pac[1];
$pdf->SetFont('Calligrapher','',9);
$pdf->Text(30, 40, iconv('UTF-8','windows-1250//TRANSLIT', ("Nazwisko i imię: ".$pac['naz']." ".$pac['imie']." PESEL:".$pac[2])));
$pdf->Ln(10);
$pdf->SetFont('Calligrapher','',14);

$sql="select * from wizyty_inf where wizyty_inf.id_wiz = ".$_GET['wiz'];
$result=mysql_query($sql);
$pac_inf = @mysql_fetch_array($result);
#
$pdf->Ln(10);
$pac_inf['wyw']=iconv('UTF-8','windows-1250//TRANSLIT', $pac_inf[1]);
$pac_inf['bad']=iconv('UTF-8','windows-1250//TRANSLIT', $pac_inf[2]);
$pac_inf['zalecenia']=iconv('UTF-8','windows-1250//TRANSLIT', $pac_inf[3]);
$pdf->MultiCell(0,5,$pac_inf['zalecenia'], 0, "J");
$osy=$pdf->GetY();
if ($_SESSION['uzytk']['podpis']<>'') $pdf->Image('../img/pieczatki/'.$_SESSION['uzytk']['podpis'],135,$osy,46);

if ($_GET['type']==d){
    $pdf->Output("../print/".$_GET['wiz'].".pdf", "F");
    #shell_exec("lpr ../print/".$_GET['wiz'].".pdf");
    
    shell_exec("lp -o media=A4 -d ".$_SESSION['global']['default_printer']." ../print/".$_GET['wiz'].".pdf | lpstat | lpstat -t" );
    #echo "<pre>$output</pre>";
    #echo "Im Here";
    #śsleep(2);
    shell_exec("rm ../print/".$_GET['wiz'].".pdf" );
    
}
else {
    $pdf->Output($pac['naz']." ".$pac['imie']." - ".  date("Ymd"), "D");
}
?>
